import 'dart:ui' as ui;
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';

///文字转图片转换器
class LedConverter {
  ///文字转ui.Picture
  static ui.Picture convert({
    required String text,
    required Offset canvasSize,
  }) {
    final recorder = ui.PictureRecorder();
    final canvas = Canvas(recorder, Rect.fromPoints(const Offset(0.0, 0.0), canvasSize));

    const Color color = Colors.white;
    print("///////////////////////////// ${canvasSize.dx * (100 / 100)}");

    TextSpan span = TextSpan(
        style: const TextStyle(
            fontFamily: "Poppins",
            color: color,
            fontSize: 12,
            // fontWeight: FontWeight.normal,
            // fontStyle: FontStyle.italic,
        ),
        // style: GoogleFonts.abel(
        //   // textStyle: Theme.of(context).textTheme.headline4,
        //   fontSize: canvasSize.dx * (150 / 100),
        //   fontWeight: FontWeight.normal,
        //   color: color,
        // ),
        text: text);
    TextPainter tp = TextPainter(
      text: span,
      textDirection: TextDirection.ltr,

      // textAlign: TextAlign.center
    );

    tp.layout(
      // minWidth: 0,
      // maxWidth: double.infinity,
    );

    final offset = Offset(
      0.0,///距离画左边距
      0.0///距离画上边距
    );

    ///canvas 文本在这个画布上绘制
    ///offset 文字的定位 x大，向右，y大向下
    tp.paint(canvas, offset);
    ui.Picture s= recorder.endRecording();
    return s;
  }
  
}
